#include "StompedReality/Components/RenderInfoComponent.h"
#include "StompedReality/Core/Game.h"
#include "StompedReality/Core/Memory/ObjectPool.h"
#include "StompedReality/Core/Memory/ObjectPoolManager.h"
#include <UnitTest++.h>
using namespace StompedReality::components;

static const StompedReality::ID NEW_OBJECT_ID_ADD = 0x10000;
SUITE( CMP_MEMORY_TEST )
{
  TEST( Create_Test_A )
  {
    StompedReality::TYPE_ID riTypeID =
      StompedReality::type_system::TypeSystem::GetTypeID<RenderInfoComponent>( );
    StompedReality::type_system::TypeInfo* ricType =
      StompedReality::type_system::TypeSystem::GetType< RenderInfoComponent >( );
    StompedReality::Game g;
    StompedReality::Core::ComponentObjectPool memorySystem;
    memorySystem.SetGame( &g );
    memorySystem.AddObjectPool( riTypeID,
                                ( StompedReality::Core::MemoryBlock<StompedReality::Core::Component>* )
                                StompedReality::Core::ObjectPool<RenderInfoComponent>::CreateObjectPool ( 5 ) );
    StompedReality::ID idA = memorySystem.CreateObject( riTypeID );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, idA );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( false, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 1 ) );
    CHECK_EQUAL( false, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 2 ) );
    StompedReality::ID idB = memorySystem.CreateObject( riTypeID );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 1, idB );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 1 ) );
    CHECK_EQUAL( false, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 2 ) );
    StompedReality::ID idC = memorySystem.CreateObject( riTypeID );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 2, idC );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 0 ) );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 1 ) );
    CHECK_EQUAL( true, memorySystem.HasObject( riTypeID, NEW_OBJECT_ID_ADD + 2 ) );

    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 0, memorySystem.GetObject( riTypeID, NEW_OBJECT_ID_ADD + 0 )->GetID( ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 1, memorySystem.GetObject( riTypeID, NEW_OBJECT_ID_ADD + 1 )->GetID( ) );
    CHECK_EQUAL( NEW_OBJECT_ID_ADD + 2, memorySystem.GetObject( riTypeID, NEW_OBJECT_ID_ADD + 2 )->GetID( ) );
  }
}